<template>
	<div class="content">
		<div class="list">
			<div class="item" v-for="(t, i) in recordList" :key="i">
				<h1>{{ t.encryptName }} | {{ t.encryptIdCard }}</h1>
				<p>{{ t.dateTime }}</p>
				<p>{{ t.businessTypeName }}</p>
				<div class="result-msg" :class='{ "error": t.result != "认证成功" }'>{{ t.result }}</div>
        <van-button type="primary" size="small" @click="verificationAdd(t)">重新推送</van-button>
			</div>
		</div>
		<van-pagination v-if="recordList.length>0" v-model="searchForm.currentPage" :page-count="total" mode="simple" @change="pageChange" />
	</div>
</template>

<script>
import {
	mapState,
	mapMutations,
	mapActions
} from 'vuex'
import {
  verificationAdd,
  verificationGetPage,
} from "@/api/index";
import {
  decryptByDES, hideStrForName, hideStrForIdCard, encryptByDES
} from "@/utils/index";
import dayjs from 'dayjs';
export default {
	data() {
		return {
			list: [],
			searchForm: {
				pageSize: 3, //每页数据个数
				currentPage: 1, //当前页码
			},
			total: 0,
			loading: false,
		}
	},
	computed: {
		...mapState(['userInfo', 'config', 'deviceInfo', 'desKey','recordList']),
		title() {
			return this.$route.meta.title
		}
	},
	mounted() {
    console.log('recordList',this.recordList)
		this.getList();
	},
	methods: {
		...mapMutations(['setUserInfo']),
		hideStrForName, hideStrForIdCard,
		async getList() {
      this.total=this.recordList.length;
      return
			this.loading = true;
			const res = await verificationGetPage({
				"currentPage": this.searchForm.currentPage,
				"pageSize": this.searchForm.pageSize,
				"dynamicFilter": {
					"field": "",
					"operator": 0,
					"value": "",
					"logic": 0,
					"filters": []
				},
				"filter": {
					"createdUserName": "",
					"userName": "",
					"sn": this.deviceInfo.sn||'SMIT3B2019C08000315'
				}
			})
			this.loading = false;
			if (res.success) {
				let data = decryptByDES(res.data, this.desKey);
				data = JSON.parse(data);
				console.log(data)
				if (data.List.length > 0) {
					data.List = data.List.map((t) => {
						return {
							...t,
							name: t.UserName,
							idCard: t.UserIdCard,
							encryptName: t.UserName,
							encryptIdCard: t.UserIdCard,
							dateTime: dayjs(t.CertificationTime).format('YYYY-MM-DD HH:mm:ss'),
							businessTypeName: t.PrimarySceneName,
							result: t.VerificationResult,
						}
					})
					this.list = data.List;
					this.total = Math.floor(data.Total/this.searchForm.pageSize)+1;
					// this.total = data.Total;
				}

			}
		},
		pageChange(e) {
			this.getList()
		},
    async verificationAdd(t) {
      let data = {
        "sn": t.sn,
        "primarySceneCode": t.primarySceneCode,
        "primarySceneName": t.primarySceneName,
        "secondarySceneCode": "",
        "secondarySceneName": "",
        "userName": t.userName,
        "userIdCard": t.userIdCard,
        "verificationResult": t.verificationResult,
        "operator": "xuhui",
        "verifier": "xuhui",
        certificationTime: t.certificationTime,
        faceIdCard: t.faceIdCard,
        faceName: t.faceName,
        facePhone: t.facePhone,
      }
      console.log('data',data)

      let encryptData = encryptByDES(JSON.stringify(data), this.desKey)
      const res = await verificationAdd({
        data: encryptData,
        electronicSignature: "",
        // verificationPhoto: this.userInfo.verificationPhoto,
        idCardPhoto: "",
        // apiModel: {
        // 	idCardPhoto: this.userInfo.headerPic
        // }
      })
      if (res.success) {
        this.form = res.data
        // this.form.dsfMsg="第三方系统调用异常"
        if (this.form.dsfMsg) {
          XhAggregation.speak({
            text: this.form.dsfMsg
          })
        }
        // this.clearUserInfo()
      }
    },
		toResult(t) {
			this.setUserInfo({
				...t
			})
			this.$router.push({
				path: "result"
			})
		}
	}
};
</script>
<style lang="less" scoped>
.content {
	.list {
		height: 470px;
		overflow: auto;
		padding: 20px;

		.item {
			border-radius: 8px;
			padding: 10px 20px;
			margin-bottom: 10px;
			border: 1px solid #dfdfdf;
			background: #fff;
			position: relative;

			.result-msg {
				position: absolute;
				right: 10px;
				bottom: 10px;
				background: #19be6b;
				color: #fff;
				padding: 5px 10px;
				border-radius: 5px;

				&.error {
					background: red;
				}
			}

			h1 {
				font-size: 18px;
				font-weight: bold;
				margin-bottom: 15px;
			}

			p {
				font-size: 16px;
				line-height: 24px;
				margin: 10px 0;
			}
		}
	}

	.submit-btn {
		width: 90%;
		margin: 0 auto;
	}

	.van-pagination {
		margin-top: 10px;
		padding: 0 20px;
	}
}
</style>